<template>
  <div class="app-container">
    <!-- 查询区域 -->
    <el-form :model="queryParams" :ref="queryFormRef" inline v-show="showSearch" label-width="auto" @keyup.enter.native="handleQuery">
        <el-form-item label="关键字" prop="keywords" >
          <el-input v-model="queryParams.keywords" placeholder="请输入关键字" clearable />
        </el-form-item>
        <el-form-item label="商品ID" prop="prodId">
          <el-input-number v-model="queryParams.prodId" placeholder="商品ID" clearable />
        </el-form-item>
        <el-form-item label="订单号" prop="orderNumber">
          <el-input v-model="queryParams.orderNumber" placeholder="订单号" clearable />
        </el-form-item>
        <el-form-item label="订单项ID" prop="orderItemId">
          <el-input-number v-model="queryParams.orderItemId" placeholder="订单项ID" clearable />
        </el-form-item>
        <el-form-item label="评论用户ID" prop="userId">
          <el-input v-model="queryParams.userId" placeholder="评论用户ID" clearable />
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="tool-bar-btn">
      <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-hasPerms="['mall:prodComm:add']">新增</el-button>
      <el-button type="success" icon="el-icon-edit" :disabled="single" @click="handleUpdate" v-hasPerms="['mall:prodComm:edit']">修改</el-button>
      <el-button type="success" icon="el-icon-tickets" :disabled="single" @click="handleDetail" v-hasPerms="['mall:prodComm:detail']">详情</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="multiple" @click="handleDelete" v-hasPerms="['mall:prodComm:remove']">删除</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </div>
    
    <!-- 表格区域 -->
    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table :ref="dataTableRef" v-loading="loading" :data="dataList" stripe border @selection-change="onSelectChange" 
          :default-sort = "defaultSort" @sort-change="onSortChange" :row-key="rowKey">
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="编号" align="center" prop="id" sortable="custom" width="80"/>
      <el-table-column label="商品ID" align="center" prop="prodId"  width="150" />
      <el-table-column label="订单号" align="center" prop="orderNumber"  width="150" />
      <el-table-column label="订单项ID" align="center" prop="orderItemId"  width="150" />
      <el-table-column label="评论用户ID" align="center" prop="userId"  width="150" />
      <el-table-column label="评价" align="center" prop="evaluateDictText" width="120"/>
      <el-table-column label="评论内容" align="center" prop="content" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="得分，0-5分" align="center" prop="score"  width="150" />
      <el-table-column label="掌柜回复" align="center" prop="replyContent" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="回复时间" align="center" prop="replyTime" width="180"/>
      <el-table-column label="是否已回复" align="center" prop="replyStatusDictText" width="120"/>
      <el-table-column label="IP来源" align="center" prop="postip"  width="150" />
      <el-table-column label="有用的计数" align="center" prop="usefulCounts"  width="150" />
      <el-table-column label="晒图的图片" align="center" prop="pics" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="是否匿名" align="center" prop="isAnonymousDictText" width="120"/>
      <el-table-column label="是否显示，1:为显示，0:待审核， -1：不通过审核，不显示。 如果需要审核评论，则是0,，否则1" align="center" prop="statusDictText" width="120"/>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="200">
        <template slot-scope="{row}">
          <el-button type="text" icon="el-icon-edit" @click="handleUpdate(row)" v-hasPerms="['mall:prodComm:edit']">修改</el-button>
          <el-button type="text" icon="el-icon-tickets" @click="handleDetail(row)" v-hasPerms="['mall:prodComm:detail']">详情</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(row)" v-hasPerms="['mall:prodComm:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination v-show="!loading" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"  @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <EditProdComm ref="formDialog" @ok="getList" />

  </div>
</template>

<script>
import {httpGet, httpDel} from '@/api';
import { IndexListMixin } from '@/components/mixins/IndexListMixin';
import EditProdComm from './edit';

export default {
  name: "ProdComm",
  mixins:[IndexListMixin],
  components: {
    EditProdComm,
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        keywords: null,
        prodId: null,
        orderNumber: null,
        orderItemId: null,
        userId: null,
        pageNum: 1,
        pageSize: 10
      },
      url: {
        base: '/mall/prodComm/',
      	list: '/mall/prodComm/list'
      }
    };
  },
  created() {
    this.getList();
  },
  mounted(){
  },
  methods: {
    getList() {
      this.loadData(this.url.list);
    },
    
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.formDialog.toAdd("添加商品评论");
    },
    
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.selectedRowKeys
      this.$refs.formDialog.toUpdate("修改商品评论", httpGet(this.url.base + id));
    },
    
    /** 查看详情按钮操作 */
    handleDetail(row) {
      const id = row.id || this.selectedRowKeys
      this.$refs.formDialog.toDetail("查看商品评论详情", httpGet(this.url.base + id));
    },
    
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.selectedRowKeys
      this.deleteData(this.url.base, ids);
    },

  }
};
</script>
